﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeChat.Common;
using BLL;
using System.IO;

namespace WeChat.Common2
{
    public class Config
    {
        static DataTable dt = WxPayAddBLL.getAliPayInfo();
        #region //支付宝配置

        public static string alipay_public_key = dt.Rows.Count==0 ? "" : dt.Rows[0]["alipay_public_key"].ToString();
        //沙箱环境支付宝公钥
        //public static string alipay_public_key = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7pPkaaN8rhktrTkaJ8rdUxQ8Ue8gZlUvkPowfUN/L8PQplEE850CDwoIJ4A+0HAHUQyPiEqG6ribpzNg726piulm1gP6vB2IoyOkXD1Q4PGHxmDmCkDmXe1JxV8yuRagyllSrlAbNqx2GT1+plSv4u+SNkpzmStllxDF2+xN0ZS/vt+f/mW3vvUbGq7ccFdLdNc6x6zml0rxrrMkEDOp0s0+KmOld+pRIxNkXLZExWvZzvkUE15updGXFIpEn4HTCeEDPRGRgRtnTE7ZIA80wI1puFBoVXx3F/sL0z80s+bDkOosBld+1zaEObGhLKsTKZKPNaTOx8ZslgXTf+U44QIDAQAB";
        

        //这里要配置没有经过的原始私钥

        //开发者私钥
        public static string merchant_private_key = dt.Rows.Count == 0 ? "" : dt.Rows[0]["merchant_private_key"].ToString();
        //沙箱环境开发者私钥
        //public static string merchant_private_key = @"MIIEpQIBAAKCAQEA39cZA8X/UK6W9ZUK06JQN19v5IJ2M8xro1zokirG8noh0diaAzkZ1OWbbN+Wcw/CV66vU2X8YyLe9mo73ucGb36CoPuh+PXZkR3PvB8QZOo/UBzlRVHObaDu8LK0Vs0nPSghn1EzQ7wmYrxjKqOV8zX2myYbA9z/PWhg9tza2vUZwvsuIcwvn3hmlEJkbyuJEy8RmZIyw1uTfI/s8XisSUXO/loksxAU+HlYa3O52kfjYR4Uq9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+1nW81puImohScDbuE3hKxnlJB42+QWRSEO5j5GVlJingt9rgjP+MWPDw6pTWpyAWZPZyMlERs4FeYsp+TSH4UCgYEAsBjAGSkNR7XajD9MkT+9+PzMwCX377c7KDmsFPaUMrnSjAd/XUEYVR1kBbGItLINovqadqizwhK20SD37GkX2UCn126ZMp7ARKok9uzoEih+Hc1Rqy3vtpMx9m7SdNR1swG1AhnFXabqaBxpsvGPd2v9YgHKHflZydhF2crEl3E=";

        //开发者公钥
        public static string merchant_public_key = dt.Rows.Count == 0 ? "" : dt.Rows[0]["merchant_public_key"].ToString();
        //沙箱环境开发者公钥
        //public static string merchant_public_key = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA39cZA8X/UK6W9ZUK06JQN19v5IJ2M8xro1zokirG8noh0diaAzkZ1OWbbN+Wcw/CV66vU2X8YyLe9mo73ucGb36CoPuh+PXZkR3PvB8QZOo/UBzlRVHObaDu8LK0Vs0nPSghn1EzQ7wmYrxjKqOV8zX2myYbA9z/PWhg9tza2vUZwvsuIcwvn3hmlEJkbyuJEy8RmZIyw1uTfI/s8XisSUXO/loksxAU+HlYa3O52kfjYR4Uq9RbDNPa+wt6IP18uroF3ktMjkHyv2IOF/Ycf4YJmyMIhgJ7B7+GBfbfA8xtHp+QLEn8VOhfy45s1V5iy+MGwCyjEBpzdP1dAvl+YwIDAQAB";

        /// <summary>
        /// 应用ID
        /// </summary>
        public static string appId = dt.Rows.Count == 0 ? "" : dt.Rows[0]["appId"].ToString();
        //沙箱环境appid
        //public static string appId = "2016080100140787";

        /// <summary>
        /// 合作伙伴ID：partnerID
        /// </summary>
        public static string pid = dt.Rows.Count == 0 ? "" : dt.Rows[0]["pid"].ToString();
        //沙箱环境 pid
        //public static string pid = "2088102169443194";

        /// <summary>
        /// 支付宝网关
        /// </summary>
        public static string serverUrl = "https://openapi.alipay.com/gateway.do";
        //沙箱环境serverUrl
        //public static string serverUrl = "https://openapi.alipaydev.com/gateway.do";
        public static string mapiUrl = "https://mapi.alipay.com/gateway.do";
        public static string monitorUrl = "http://mcloudmonitor.com/gateway.do";

        //编码，无需修改
        public static string charset = "utf-8";
        //签名类型，支持RSA2（推荐！）、RSA
        public static string sign_type = "RSA2";
        //版本号，无需修改
        public static string version = "1.0";


        /// <summary>
        /// 公钥文件类型转换成纯文本类型
        /// </summary>
        /// <returns>过滤后的字符串类型公钥</returns>
        public static string getMerchantPublicKeyStr()
        {
            StreamReader sr = new StreamReader(merchant_public_key);
            string pubkey = sr.ReadToEnd();
            sr.Close();
            if (pubkey != null)
            {
                pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("\r", "");
                pubkey = pubkey.Replace("\n", "");
            }
            return pubkey;
        }

        /// <summary>
        /// 私钥文件类型转换成纯文本类型
        /// </summary>
        /// <returns>过滤后的字符串类型私钥</returns>
        public static string getMerchantPriveteKeyStr()
        {
            StreamReader sr = new StreamReader(merchant_private_key);
            string pubkey = sr.ReadToEnd();
            sr.Close();
            if (pubkey != null)
            {
                pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("\r", "");
                pubkey = pubkey.Replace("\n", "");
            }
            return pubkey;
        }
        #endregion


        #region//微信配置  服务器ip和域名建议在web.config中设置

        static SetBasicInfoBLL  baseInfo = new SetBasicInfoBLL();
        static DataTable dt2 = baseInfo.getWechatBaseInfo();
        //===============【公众号appID】================
        public static string getAppID()
        {
            string appId = dt2.Rows[0]["appId"] == null ? "" : dt2.Rows[0]["appId"].ToString();
            return appId;
        }

        //===============【公众号appSecret】================
        public static string getAppSecret()
        {
            string appSecret = dt2.Rows[0]["appSecret"] == null ? "" : dt2.Rows[0]["appSecret"].ToString();
            return appSecret;
        }

        //===============【接入token】================
        public static string getToken()
        {
            string token = dt2.Rows[0]["token"] == null ? "" : dt2.Rows[0]["token"].ToString();
            return token;
        }


        //===============【消息加密解密密钥EncodingAESKey】================
        public static string getEncodingAESKey()
        {
            string EncodingAESKey = dt2.Rows[0]["EncodingAESKey"] == null ? "" : dt2.Rows[0]["EncodingAESKey"].ToString();
            return EncodingAESKey;
        }



        //===============【连接客服返回文本】================
        public static string getKefuReturn(string state)
        {
            string content = "\n当前在线客服：\n" + state + "\n如当前无客服在线，您也可以留言，客服上线后即可收到您的信息/调皮！\n请输入话语：";
            return content;
        }


        /*****************************【支付类】*************************/


        static DataTable dt3 = WxPayAddBLL.getWxPayInfo();

        //===============【附加数据】==============================
        /*
         * 在查询API和支付通知中原样返回，该字段主要用于商户携带订单的自定义数据
         */
        public static string attach = "支付测试1";


        //===============【商品或支付单简要描述】=======================
        public static string body = dt3.Rows[0]["body"] == null ? "" : dt3.Rows[0]["body"].ToString();


        //===============【商品名称】==========================
        //public static string goodsName = "商品名称";


        //===============【商品ID】==========================
        /*
         * trade_type=NATIVE，（扫码支付）此参数必传。此id为二维码中包含的商品ID，商户自行定义。
         */
        public static string product_id = dt3.Rows[0]["product_id"] == null ? "" : dt3.Rows[0]["product_id"].ToString();//"sz_JOCAT";


        //===============【商户名称】===================
        public static string CompanyName = dt3.Rows[0]["CompanyName"] == null ? "" : dt3.Rows[0]["CompanyName"].ToString();//"深圳市优卡特电子有限公司";


        //===============【商户系统后台机器IP】==================
#pragma warning disable CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        public static string ip = ConfigurationSettings.AppSettings["ip"].ToString();//"120.25.59.199";
#pragma warning restore CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”


        //===============【域名设置】=================
#pragma warning disable CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        public static string domainName = ConfigurationSettings.AppSettings["domainName"].ToString();//"wechat.jocat.com";
#pragma warning restore CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”


        //===============【接收微信支付异步通知回调地址】==================
        public static string ReUrl = "http://" + domainName + "/JsSDK/WxPay/ResultNotifyPage.aspx";

        //===============【接收汇耘富异步通知回调地址】==================
        public static string ReUrls = "http://" + domainName + "/WeChat/HyfPay/ResultPage.aspx";


        //===============【微信商户号merchantNum】================
        public static string getMerchantNum()
        {
            string merchantNum = dt3.Rows[0]["merchantNum"] == null ? "" : dt3.Rows[0]["merchantNum"].ToString();
            return merchantNum;
        }

        //===============【微信商户密钥payKey】================
        public static string getPayKey()
        {
            string payKey = dt3.Rows[0]["payKey"] == null ? "" : dt3.Rows[0]["payKey"].ToString();
            return payKey;
        }

        //===============【充值成功返回文本】=================
        public static string setPayReturn(double money,string time,string rfye)
        {
            LoginBLL lb = new LoginBLL();
            if (lb.IsOnline())//联机
            {
                return "您已成功充值： " + money + "元 \n" + rfye + "充值时间：\n" + time + "\n您可在充值记录中查看详细信息哦/调皮";
            }
            else//脱机
            {
                return "您已成功预充值： " + money + "元 \n" + "充值时间：\n" + time + "\n 请于自助充值端进行读卡充值即可到账！";
            }
        }
        //===============【订餐成功返回文本】=================
        public static string setOrderReturn(string  order, double total_fee)
        {


                return "您已订餐成功：\n 订单号：" + order + "\n订单总金额：" + total_fee + "元\n请稍后就餐！";
            // return "您已订餐成功：\n 订单号：" + order + "\n订单总金额：" + total_fee + "元\n请按时去食堂就餐！";
        }
        #endregion
    }
}
